import socket,time
import threading
def tcplink(sock,addr):
    print('接收到新的连接从%s:%s..' % addr)
    sock.send('欢迎！！！'.encode('utf-8'))
    while True:
        data=sock.recv(1024)
        time.sleep(1)
        if not data or data.decode('utf-8')=='exit':
            break
        sock.send(('你好 %s' % data.decode('utf-8')).encode('utf-8'))
    sock.close()
    print('连接关闭：%s:%s' % addr)
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('127.0.0.1',1985))
s.listen(5)
print('等待连接……')
while True:
    sock,addr=s.accept()
    t=threading.Thread(target=tcplink,args=(sock,addr))
    t.start()